package com.sdleyou.treepro.manager.api.map;

import com.sdleyou.treepro.common.model.utils.ResultVOUtil;
import com.sdleyou.treepro.common.model.vo.AreaVO;
import com.sdleyou.treepro.common.model.vo.MapVO;
import com.sdleyou.treepro.common.model.vo.RegionVO;
import com.sdleyou.treepro.common.model.vo.ResultVO;
import com.sdleyou.treepro.common.service.MapManager;
import com.sdleyou.treepro.system.version.ApiVersion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 地图控制器
 *
 * @author gx
 * @version v1.0
 * 2020年2月21日
 */
@RestController
@RequestMapping("/api")
public class ManagerMapController {
    @Autowired
    private MapManager mapManager;

    /**
     * 创建基地
     *
     * @param mapVO
     * @return
     * @version v1.0
     */
    @ApiVersion(1)
    @PostMapping("/{version}/manager/map")
    public ResultVO create(@RequestBody MapVO mapVO) {
        return ResultVOUtil.success(mapManager.createMap(mapVO));
    }

    /**
     * 获取基地列表
     *
     * @return
     * @version v1.0
     */
    @ApiVersion(1)
    @GetMapping("/{version}/manager/map")
    public ResultVO list(@RequestParam(value = "page_num", defaultValue = "1") Integer pageNum,
                         @RequestParam(value = "page_size", defaultValue = "5") Integer pageSize,
                         @RequestParam(value = "sort", defaultValue = "1") Integer sort,
                         @RequestParam(value = "keywords", defaultValue = "") String keywords) {
        return ResultVOUtil.success(mapManager.mapList(pageNum, pageSize, keywords, sort));
    }

    @ApiVersion(1)
    @PutMapping("/{version}/manager/map/{base_id}")
    public ResultVO update(@PathVariable("base_id") String baseId,
                           @RequestBody MapVO mapVO) {
        mapManager.updateMap(baseId, mapVO);
        return ResultVOUtil.success();
    }

    /**
     * 创建基地下面的区域
     *
     * @return
     * @version v1.0
     */
    @ApiVersion(1)
    @PostMapping("/{version}/manager/area/{base_id}")
    public ResultVO createArea(@PathVariable("base_id") String baseId,
                               @RequestBody AreaVO areaVO) {
        mapManager.createArea(baseId, areaVO);
        return ResultVOUtil.success();
    }

    /**
     * 修改基地下区域信息
     *
     * @param areaId
     * @param areaVO
     * @return
     * @version v1.0
     */
    @ApiVersion(1)
    @PutMapping("/{version}/manager/area/{area_id}")
    public ResultVO updateArea(@PathVariable("area_id") String areaId,
                               @RequestBody AreaVO areaVO) {
        mapManager.updateArea(areaId, areaVO);
        return ResultVOUtil.success();
    }

    /**
     * 创建区域下的植树区
     *
     * @param areaId
     * @return
     * @version v1.0
     */
    @ApiVersion(1)
    @PostMapping("/{version}/manager/region/{area_id}")
    public ResultVO createRegion(@PathVariable("area_id") String areaId,
                                 @RequestBody RegionVO regionVO) {
        mapManager.createRegion(areaId, regionVO);
        return ResultVOUtil.success();
    }

    /**
     * 修改植树区
     *
     * @return
     * @version v1.0
     */
    @ApiVersion(1)
    @PutMapping("/{version}/manager/region/{region_id}")
    public ResultVO updateRegion(@PathVariable("region_id") String regionId,
                                 @RequestBody RegionVO regionVO) {
        mapManager.updateRegion(regionId, regionVO);
        return ResultVOUtil.success();
    }

    /**
     * 批量导入excel坑位
     */
    @ApiVersion(1)
    @PostMapping("/{version}/manager/well/{region_id}")
    public ResultVO importExcel(HttpServletRequest request,
                                @PathVariable("region_id") String regionId) {
        mapManager.importService(request, regionId);
        return ResultVOUtil.success();
    }


}
